/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2013-2021.
 * Description: support dma init
 * Author: xiekunxun <xiekunxun@huawei.com>
 * Create: 2013-11-08
 */

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/hal32/hal_dma_init.h>

#define DMA_DTS_STRING		"arm,dma"
#define DMA_DTS_FLAG		"dma_cache_flag"

unsigned int dma_cache_flag __read_mostly = DMA_USE_NORMAL;
EXPORT_SYMBOL(dma_cache_flag);

static __init int dma_dts_init(void)
{
	struct device_node *node;
	int ret;

	node = of_find_compatible_node(NULL, NULL, DMA_DTS_STRING);
	if (WARN_ON(!node)) {
		printk(KERN_WARNING"[%s]find dts node error, use default value!\n", __func__);
		dma_cache_flag = DMA_USE_NORMAL;
		ret = -ENOENT;
		goto out;
	}

	ret = of_property_read_u32(node, DMA_DTS_FLAG, &dma_cache_flag);
	if (ret) {
		printk(KERN_WARNING"[%s]find flag node error, use default value!\n", __func__);
		dma_cache_flag = DMA_USE_NORMAL;
		goto out;
	}

	if (DMA_USE_NORMAL != dma_cache_flag && DMA_USE_ENHANCE != dma_cache_flag) {
		printk(KERN_WARNING"[%s]dma cache flag is error:%d, use default value!", __func__, dma_cache_flag);
		dma_cache_flag = DMA_USE_NORMAL;
		ret = -EINVAL;
	}

out:
	printk(KERN_INFO"[%s]dma cache flag is %d\n", __func__, dma_cache_flag);
	return ret;
}

core_initcall(dma_dts_init);
